package cn.jee.cs.repo;

import cn.jee.cs.model.Course;
import cn.jee.cs.model.Student;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface StudentRepository extends CrudRepository<Student, Long> {
    /**
     * 使用JPQL查询没有选择指定课程的学生
     *
     * @param course
     * @return
     */
    @Query(value = "SELECT s" +
            " FROM Student s " +
            " WHERE s not in( " +
            " SELECT cs.student " +
            " FROM CourseStudent cs " +
            " WHERE cs.course = ?1)")
    List<Student> findStudentsByNotChosenCourse(Course course);
}
